package com.grantz.function.bbs.core.controller;

import javax.annotation.Resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.grantz.function.bbs.core.inter.DiscussTypeService;
import com.grantz.model.bbs.DiscussTypeModel;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 文件名称： com.grantz.function.bbs.core.controller.DiscussTypeController.java</br>
 * 初始作者： WenBin</br>
 * 创建日期： 2020年3月1日</br>
 * 功能说明： 帖子类型，分类 <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者        日期       修改内容<br/>
 * ================================================<br/>
 *  Copyright (c) 2010-2011 .All rights reserved.<br/>
 */
@RestController
@RequestMapping("/api/v1/discusstype")
@Api(value="论点类型接口",tags={"论点类型接口"})
public class DiscussTypeController {

	@Resource
	private DiscussTypeService  discussTypeService;

	@ApiOperation(value = "添加信息")
	@PutMapping
	public ResponseEntity<DiscussTypeModel>  save(@RequestBody DiscussTypeModel model){
		DiscussTypeModel  rt = null ;
		try {
			rt=discussTypeService.add(model);
			return new ResponseEntity<>(rt,HttpStatus.CREATED);
		} catch (Exception e) {

		}
		return new ResponseEntity<>(HttpStatus.NOT_FOUND);
	}
	
	@ApiOperation(value = "更新")
	@PostMapping
	public ResponseEntity<DiscussTypeModel>  update(@RequestBody DiscussTypeModel model){
		DiscussTypeModel  rt = null ;
		try {
			rt=discussTypeService.update(model);
			return new ResponseEntity<>(rt,HttpStatus.CREATED);
		} catch (Exception e) {

		}
		return new ResponseEntity<>(HttpStatus.NOT_FOUND);
	}
	
	@ApiOperation(value = "用过主键查找")
	@GetMapping("one")
	public ResponseEntity<DiscussTypeModel>  getOne(@RequestParam("id")  String id){
		DiscussTypeModel  rt=discussTypeService.findOneById(id);
		if(rt!=null) {
			return new ResponseEntity<>(rt,HttpStatus.CREATED);
		}
		return new ResponseEntity<>(HttpStatus.NOT_FOUND);
	}
	
	@ApiOperation(value = "用过typeno查找")
	@GetMapping("/api/v1/discusstype/typeno")
	public ResponseEntity<DiscussTypeModel>  getOneByTypeNo(@RequestParam("typeNo")  Long typeno){
		DiscussTypeModel  rt=discussTypeService.findOneByTypeNo(typeno);
		if(rt!=null) {
			return new ResponseEntity<>(rt,HttpStatus.CREATED);
		}
		return new ResponseEntity<>(HttpStatus.NOT_FOUND);
	}
}
